<?php
if(isset($_POST['submit']))
{
	$guid = $_POST['char'];
    $account = $_POST['username'];
	$location = $_POST['location'];
	$acct = "";
	$race = "";
    $level = "";


	$account = mysql_real_escape_string($account);
	$password = mysql_real_escape_string($password);
	$character = mysql_real_escape_string($character);
	$location = mysql_real_escape_string($location);

	$query = "SELECT race, level, gold FROM characters WHERE  guid = '".$guid."'";

	$result = mysql_query($query, $char) or die("Error #1: " . mysql_error());
	$numrows = mysql_num_rows($result);

	if ($numrows == 0)
	{
		die("<center>That character does not exist on that account!</center>");
	}

	$row = mysql_fetch_array($result);
	$race = $row[0];
    $level = $row[1];

	if($row[2] < (5 * 10000))
	{
		die("<center>Your character does not have enough gold to be teleported</center>");
	}
	$gold = $row[2];

	$map = "";
	$x = "";
	$y = "";
	$z = "";
	$place = "";

	switch($location)
	{
		//stormwind
		case 1:
			$map = "0";
			$x = "-8913.23";
			$y = "554.633";
			$z = "93.7944";
			$place = "Stormwind City";
			break;
		//ironforge
		case 2:
			$map = "0";
			$x = "-4981.25";
			$y = "-881.542";
			$z = "501.66";
			$place = "Ironforge";
			break;
		//darnassus
		case 3:
			$map = "1";
			$x = "9951.52";
			$y = "2280.32";
			$z = "1341.39";
			$place = "Darnassus";
			break;
		//exodar
		case 4:
			$map = "530";
			$x = "-3987.29";
			$y = "-11846.6";
			$z = "-2.01903";
			$place = "The Exodar";
			break;
		//orgrimmar
		case 5:
			$map = "1";
			$x = "1676.21";
			$y = "-4315.29";
			$z = "61.5293";
			$place = "Orgrimmar";
			break;
		//thunderbluff
		case 6:
			$map = "1";
			$x = "-1196.22";
			$y = "29.0941";
			$z = "176.949";
			$place = "Thunder Bluff";
			break;
		//undercity
		case 7:
			$map = "0";
			$x = "1586.48";
			$y = "239.562";
			$z = "-52.149";
			$place = "The Undercity";
			break;
		//silvermoon
		case 8:
			$map = "530";
			$x = "9473.03";
			$y = "-7279.67";
			$z = "14.2285";
			$place = "Silvermoon City";
			break;
		//shattrath
		case 9:
			$map = "530";
			$x = "-1863.03";
			$y = "4998.05";
			$z = "-21.1847";
			$place = "Shattrath";
			break;
		//for unknowness -> shattrath
		default:
			die("<center>That is an invalid location!</center>");
			break;
	}

	//disallows factions to use enemy portals
	switch($race)
	{
		//alliance
		case 1:
		case 3:
		case 4:
		case 7:
		case 11:
			if((($location >=5) && ($location <=8)) && ($location != 9))
			{
				die("<center>Alliance players can not teleport to horde areas!<br><br></center>");
			}
			break;
		//horde
		case 2:
		case 5:
		case 6:
		case 8:
		case 10:
			if ((($location >=1) && ($location <=4)) && ($location != 9))
			{
				die("<center>Horde players can not teleport to alliance areas!<br><br></center>");
			}
			break;
		default:
			die("<center>That is not a valid race!<br><br></center>");
			break;
	}

    if($level < 58 && $location == 9)
    {
    	die("<center>Require at least lvl 58!</center>");
    }

	$newGold = $gold - (5 * 10000);

	$query = "UPDATE characters SET positionX = ".$x.", positionY = ".$y.", positionZ = ".$z.", mapid = ".$map.", gold = ".$newGold." WHERE guid = '".$guid."'";
	$result = mysql_query($query, $char) or die("Error #2: " . mysql_error());
	
	echo "<center>After paying off 5g, with sad look on your face,<br></center>";
	echo "<center>you are entering goblin transpoder machine...<br><br></center>";
	echo "<center>Your character has been teleported to ".$place.",<br></center>";
	echo "<center>and now has ".($newGold / 10000)." gold left.</center>";
	echo "</td></tr>";
}
else
{
    
	echo "<form name='myform' method='post' action='tool.php?teleporter'>";
    echo "<center><br><span style='font-size: 18px; font-family:Century Gothic, Arial, Helvetica; color:#ffffff'>Character Teleporter</span><br><br>";
	$user = $_SESSION['user'];
    $getuser = "SELECT * from b_users a, b_templates b where b.templateid=a.templateclass and a.username='$user'";
    $getuser2 = mysql_query($getuser, $forum) or die("Error #3: " . mysql_error());
    $getuser3 = mysql_fetch_array($getuser2);
	
	$SQLwow ="SELECT * from accounts where login='$getuser3[username]'";
	$SQLwow2=mysql_query($SQLwow, $logon) or die("Error #4: " . mysql_error());
	$SQLwow3=mysql_fetch_array($SQLwow2);
	
	$SQLawow ="SELECT * from characters where acct='$SQLwow3[acct]'";
	$char=mysql_query($SQLawow, $char) or die("Error #5: " . mysql_error());
	
	print "<table width='400px' border='0' cellspacing='0' cellpadding='0'><tr><td>";
	print "Teleport <select name='char' style=' background-color:#000033; color:#FFFFFF; border: 1px solid #333333'>";
	while ($char2 = mysql_fetch_array($char))
	{
		if ($char2['guid'] == $getuser3['charid']) {
			print "<option selected='selected' value='$char2[guid]'>-> $char2[name]</option>";
		}
		else
		{
			print "<option value='$char2[guid]'>$char2[name]</option>";
		}
	}
	print "</select>";
	print "</td><td>";
	
	echo "<center>&nbsp;to ";
	echo "<select name=location style=' background-color:#000033; color:#FFFFFF; border: 1px solid #333333'>";
	echo "<option value='1'>Stormwind</option>";
	echo "<option value='2'>Ironforge</option>";
	echo "<option value='3'>Darnassus</option>";
	echo "<option value='4'>Exodar</option>";
	echo "<option value='---------'>------------------</option>";
	echo "<option value='5'>Orgrimmar</option>";
	echo "<option value='6'>Thunder Bluff</option>";
	echo "<option value='7'>Undercity</option>";
	echo "<option value='8'>Silvermoon</option>";
	echo "<option value='---------'>------------------</option>";
	echo "<option value='9'>Shattrath</option>";
	echo "</select></td></tr></table><br>";
	echo "(Warning: Cost is 5g for 1 teleport)<br><br>";

	echo "<input type=submit name=submit value=Teleport style='background-color:#000033; color:#FFFFFF; border: 1px solid #333333'><br><br>";

	echo "</form>";
	echo "You must be logged out of game so this can work.<br />";
}
?>